package models

import (
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
	"time"
	_"github.com/go-sql-driver/mysql"
)

type Userinfo struct {
	Id int	//用户编号
	UserName string	//用户名
	UserPwd string	//用户密码
	Remark string	//备注
	AddDate time.Time	//添加日期
	ModifDate time.Time	//修改日期
	DelFlag int	//删除标记
	Roles []*Roleinfo`orm:"rel(m2m)"`
	UserActions []*Useraction `orm:"reverse(many)"`
}

type Roleinfo struct {
	Id int
	RoleName string `orm:"size(32)"`
	Remark string
	DelFlag int
	AddDate time.Time
	ModifDate time.Time
	Users []*Userinfo`orm:"reverse(many)"`
	Actions[]*Actioninfo`orm:"rel(m2m)"`
}

type Actioninfo struct {
	Id int
	Remark string
	DelFlag int
	AddDate time.Time
	ModifDate time.Time
	Url string //权限路由管理
	HttpMethod string
	ActionInfoName string
	ActionTypeEnum int
	MenuIcon string
	IconWidth int
	IconHeight int
	Roles[]*Roleinfo `orm:"reverse(many)"`
	UserActions []*Useraction `orm:"reverse(many)"`

}

type Useraction struct {
	Id int
	IsPass int
	Users *Userinfo `orm:"rel(fk)"`
	Actions *Actioninfo `orm:"rel(fk)"`
}

type Articleclass struct {
	Id int//主键
	ClassName string//类别名称
	ParentId int //父类别的编号
	CreateUserId int //创建类别的用户编号
	CreateDate time.Time //创建时间
	DelFlag int //删除标记
	Remark string //备注
	Articles []*Articleinfo`orm:"reverse(many)"`
}

type Articleinfo struct {
	Id int
	KeyWords string  //关键词
	Title string    //标题
	FullTitle string  //全标题
	Intro string  //导读
	ArticleContent string `orm:"type(text)"` //新闻内容
	Author string//作者
	Origin string//来源
	AddDate time.Time//添加日期
	ModifyDate time.Time//修改日期
	DelFlag int//删除标记
	PhotoUrl string//图片地址
	ArticleClasses []*Articleclass`orm:"rel(m2m)"`

}


func init(){
	//获取配置文件中对应的配置信息
	var (
		dbhost = beego.AppConfig.String("dbhost")
		dbport = beego.AppConfig.String("dbport")
		dbuser = beego.AppConfig.String("dbuser")
		dbpassword = beego.AppConfig.String("dbpassword")
		db = beego.AppConfig.String("db")
	)

	orm.RegisterDriver("mysql", orm.DRMySQL) //注册mysql Driver
	//构造conn连接
	conn := dbuser + ":" + dbpassword + "@tcp(" + dbhost + ":" + dbport + ")/" + db + "?charset=utf8"
	//注册数据库连接
	orm.RegisterDataBase("default", "mysql", conn)

	orm.RegisterModel(new(Userinfo),new(Roleinfo),new(Actioninfo),new(Useraction),new(Articleclass),new(Articleinfo))//注册模型
	orm.RunSyncdb("default", false, true)

}